import { Pipe, PipeTransform } from '@angular/core';
import * as moment from 'moment';
@Pipe({ name: 'timefromnow' })
export class Timefromnowpipe implements PipeTransform {
    
    constructor(){
        moment.locale('zh-cn');
    }
  transform(value: string): string {
    if(!value) return value;
    if(typeof value !== 'string') {
      throw new Error('Invalid pipe argument for WelcomePipe');
    }
    if (moment(value).isBefore(moment().subtract(23, "hours").format('YYYY-MM-DD HH:mm:ss'))) {
        return moment(value).format('MM月DD日 HH:mm');
      } else {
        return moment(value,'YYYY-MM-DD HH:mm:ss').fromNow();
      }
  }
} 